###
events: ['changed']
###

class tree.ui.RadioGroup extends tree.ui.Widget

    constructor: () ->
        @htmlelem = document.createElement 'form'
        @htmlelem.className = 'tree-radio-group'
        @children = []
        
    add: (child) ->
        if not child instanceof tree.ui.RadioButton
            throw new TypeError 'you can only put RadioButtons inside a RadioGroup'
        @children.push child
        
    show: () ->
        super
        for child in @children
            @htmlelem.appendChild child.show()
        @htmlelem

class tree.ui.RadioButton extends tree.ui.Widget
    constructor: (text) ->
        super
        @htmlelem = document.createElement 'div'
        @htmlelem.className = 'tree-radio-button'
        @radio = document.createElement 'input'
        @radio.value = text
        @radio.name = 'tree-standard'
        @label = document.createElement 'label'
        @label.innerHTML = text
        @radio.type = 'radio'
        
        @htmlelem.appendChild @label
        @htmlelem.appendChild @radio
        
        @radio.onclick = @_on_click
        
    _on_click: (widget, event) =>
        @emit 'changed', @radio.checked    
        
    set_text: (text) ->
        @label.innerHTML = text
